package org.rednebula.framework.core.utils;

import org.jbpm.api.ProcessEngine;
import org.jbpm.pvm.internal.cfg.ConfigurationImpl;
import org.rednebula.framework.core.ProcedureEngine;
import org.rednebula.framework.core.SpringConfiguration;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;



public class SpringHelper implements ApplicationContextAware {
	
	ApplicationContext context;
	protected ProcessEngine processEngine;
	
    protected String jbpmCfg = "jbpm.cfg.xml";
	
	public void setApplicationContext(ApplicationContext context)
			throws BeansException {
		this.context=context;
	}
   
	public ProcedureEngine createEngine(){
		SpringConfiguration configuration=new SpringConfiguration();
		configuration.setApplicationContext(context);
		return configuration.buildProcessEngine();
	}
	
	  public ProcessEngine createProcessEngine() {
		  processEngine=  new ConfigurationImpl()
		      .springInitiated(context)
		      .setResource(jbpmCfg)
		      .buildProcessEngine();
		  return processEngine;
	  }

}
